<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
		  <#assign base=request.contextPath  />
    <title>消防安全</title>
    <link rel="stylesheet" href="${base}/js/layui/css/layui.css" media="all">
    <style type="text/css">
        form{
            padding: 20px;
        }
        .layui-btn-radius{
            border-radius: 5px;
        }
    </style>
</head>
<body>
<fieldset class="layui-elem-field  layui-field-title" style="margin-top: 30px;">
    <legend>消防安全</legend>
</fieldset>
<div class="demoTable"style="padding:15px;">
    <button class="layui-btn layui-btn-radius" id="btn2" data-method="offset" type="button" style="background-color: #0092EF;">添加消防安全</button>
    <div class="layui-inline layui-form" style="float:right;" >
        <div class="layui-input-inline">
            <select name="modules" lay-verify="required" id="sech" lay-search="">
                <option value="">请选择要搜索的列</option>
                <option value="floor">楼层</option>
                <option value="position">方位</option>
                <option value="people">巡防人</option>
            </select>
        </div>
        <div class="layui-inline">
            <input class="layui-input" name="id" id="demoReload" autocomplete="off">
        </div>
        <button class="layui-btn layui-btn-radius" id="btn1" data-type="reload" style="background-color: #0092EF;">搜索</button>
    </div>
</div>
<table class="layui-hide"  id="test" lay-filter="user"></table>
<script type="text/html" id="barDemo">
    <i class="layui-icon layui-icon-edit"  lay-event="edit" id="updateFiesa" style="font-size: 20px;" ></i>&nbsp;&nbsp;&nbsp;
    <i class="layui-icon layui-icon-delete layui-btn-xs" lay-event="del" id="delectfiresafety" href="javascript:void(0)"  onclick="delectfiresafety('{{d.id}}')"  style="font-size: 20px;" ></i>
</script>
<script src="${base}/js/layui/layui.js" charset="utf-8"></script>
<script src="${base}/js/jquery.min.js"></script>
<script type="text/javascript" src="${base}/js/zhang.js"></script>
<script>
    layui.use(['form', 'layedit', 'laydate','table'], function(){
        var form = layui.form
                ,$ = layui.jquery
                ,layer = layui.layer
                ,layedit = layui.layedit
                ,laydate = layui.laydate
        table = layui.table;
        table.render({
            elem: '#test'
            ,url:'${base}/firesafety/selectFiresafety'
            ,title: '消防安全'
            ,toolbar: '#toolbarDemo'
            ,defaultToolbar: ['filter', 'print', 'exports']
            ,cols: [[
                {field:'id', title: 'ID',templet:function(val){return val.LAY_INDEX},align:'center',  width:60,fixed: true}
                ,{field:'createTime' ,templet:function(val){
                        return changeDateFormat(val.createTime);
                    }, title:'日期时间', align: 'center',width:180}
                ,{field:'floor', title:'楼层',width:70,align: 'center',width:80}
                ,{field:'position',title:'方位',width:60,align: 'center',width:80}
                ,{field:'people', title:'巡防人',width:120,align: 'center',width:100}
                ,{field:'safeevacuation', title:'安全疏散通道是否畅通 ',align: 'center',width:180}
                ,{field:'evacuation', title:'疏散指示标志是否齐全',align: 'center',width:180}
                ,{field:'extinguishing', title:'灭火器材配置是否配备',align: 'center',width:180,width:180}
                ,{field:'equipmentvalid', title:'灭火器材是否在有效期',align: 'center',width:180}
                ,{field:'watertap', title:'是否有消防灭火水龙头',align: 'center',width:180}
                ,{field:'electricity', title:'用电是否有违章情况',align: 'center',width:180}
                ,{field: 'right', title:'操作', toolbar: '#barDemo',width:120,align: 'center'}
            ]]
            ,id: 'testReload'
            ,page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                ,theme: '#0092EF'
                ,limit:20
            }
            ,height:500
            ,done: function(res, curr, count){
                this.where={};
            }
        });
        //搜索
        $('#btn1').on('click', function(){
            var sechLin=$("#sech").val();
            var sechData=$("#demoReload").val();
            var whereData={};
            whereData.lin=sechLin;
            whereData.data=Trim(sechData);
            whereData.page=1;
            whereData.limit=10;
            var table = layui.table;
            //表刷新方法
            table.reload('testReload', {
                url: '${base}/firesafety/selectFiresafety'
                ,where: whereData
            });

        });




        var active = {
            offset: function(othis){
                var type = othis.data('type')
                        ,text = othis.text();
                layer.open({
                    type: 2,
                    title: '录入消防信息',
                    shadeClose:false ,
                    offset: 't',
                    area:['470px','100%'],
                    content: '${base}/firesafety/firesafety_add',

                });
            }
        };
        $('#btn2').on('click', function(){
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });
        //编辑弹出层
        table.on('tool(user)', function(obj){
            var layEvent = obj.event;
            if(layEvent=="edit"){
                var data = obj.data;
                //示范一个公告层
                layer.open({
                    type: 2,
                    title: '编辑信息',
                    shadeClose:false ,
                    offset: 't',
                    area:['470px','100%'],
                    content: '${base}/firesafety/firesafety_Edit',
                    success: function (layero, index) {
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        /*selectED(iframeWin,"floor",data.floor);*/
                        iframeWin.$("#floor").val(data.floor);
                        selectED(iframeWin,"evacuation",data.evacuation);
                        selectED(iframeWin,"extinguishing",data.extinguishing);
                        selectED(iframeWin,"equipmentvalid",data.equipmentvalid);
                        selectED(iframeWin,"watertap",data.watertap);
                        selectED(iframeWin,"electricity",data.electricity);
                        selectED(iframeWin,"position",data.position);
                        iframeWin.$("#people").val(data.people);
                        selectED(iframeWin,"id",data.id);
                        selectED(iframeWin,"safeevacuation",data.safeevacuation);
                        iframeWin.$("#firesafetyId").val(data.id)
                        iframeWin.layui.form.render('select')
                    }
                });
            }
        });
        //清空搜索框
        layui.form.on('select()', function(data){
            $("#demoReload").val("")
        });
    });

    function selectED(iframe,selectID,data){
        iframe.$("#"+selectID+" option[value='"+data+"']").attr("selected", "selected");
    }

    function delectfiresafety(id){
        layer.confirm('真的要删除吗?', function(index){
            $.ajax({
                type:"POST",
                url:"${base}/firesafety/delectFiresafety",
                data:{"id":id},
                success : function(data){
                    var table = layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/firesafety/selectFiresafety'
                        ,where: {} //设定异步数据接口的额外参数
                    });
                    layer.close(index);
                }
            });

        } );
    }


    //键盘事件
    $("body").bind("keydown",function(e){
        // 兼容FF和IE和Opera
        var theEvent = e || window.event;
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code == 13) {
            //回车执行查询
            $("#btn1").click();
        }
    });









</script>
</body>
</html>
